﻿using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
using System.Diagnostics;
using System.Web;
using System.Web.Services;
using System.Configuration;
using XMK.Tadong.Biz;

namespace XMK.Tadong.Web.TJ
{
    /// <summary>
    /// tj_service 的摘要说明
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务，请取消对下行的注释。
    [System.Web.Script.Services.ScriptService]
    public class tj_service : System.Web.Services.WebService
    {
        [WebMethod]
        public string HelloWorld()
        {
            return "Hello World";
        }
        /// <summary>
        /// 通过传入一个SQL语句得到数据集
        /// </summary>
        /// <param name="Query">一个查询的SQL语句</param>
        /// <returns></returns>
        [WebMethod]
        public DataSet GetDataSet(string Query)
        {
            try
            {
                YQCJDBLL bll = new YQCJDBLL();

                DataSet myDataSet = bll.QueryDataReturnDataSet(Query);
                return myDataSet;
               
            }
            catch (Exception ex)
            {
                return DataError(ex);
            }

        }
        
        /// <summary>
        /// 抛出的DATASET的错误
        /// </summary>
        /// <param name="ex"></param>
        /// <returns></returns>
        public DataSet DataError(Exception ex)
        {
            DataSet errDS = new DataSet("Errors");
            DataTable errTable = errDS.Tables.Add("Error");
            errTable.Columns.Add("Message");
            errTable.Rows.Add(new Object[] { ex.Message });
            return errDS;
        }

        /// <summary>
        /// 向xmk_a_z_sy03中插入砂岩统计的数据．
        /// </summary>
        /// <param name="djdmstr">统计代码，形如hjy/2014-07-07/砂岩</param>
        /// <param name="strjh">井号，形如：敖４</param>
        /// <param name="CWStr">层位，形如：葡萄花</param>
        /// <param name="dlX">井的Ｘ坐标值</param>
        /// <param name="dlY">井的Ｙ坐标值</param>
        /// <param name="djsdfl1">顶界深度</param>
        /// <param name="djsdfl2">底界深度</param>
        /// <param name="hdfl">厚度，为底界深度－顶界深度</param>
        /// <param name="maxf">最大厚度</param>
        /// <param name="minf">最小厚度</param>
        /// <param name="avel">平均厚度</param>
        /// <param name="ljzl">累计厚度</param>
        /// <param name="sdbf">砂地比</param>
        /// <returns>布尔类型，如果插入为真，则返回ＴＲＵＥ；否则，返回ＦＡＬＳＥ</returns>
        [WebMethod]
        public bool WriteToDB(string djdmstr, string strjh, string CWStr, double dlX, double dlY, double djsdfl1, double djsdfl2, double hdfl, string maxf, string minf, double avel, double ljzl, double sdbf)
        {
            try
            {
                YQCJDBLL bll = new YQCJDBLL();
                string inser = "insert into xmk_a_z_sy03(DJDM, JH ,CW,ZBX,ZBY,DINGJSD,DIJSD,HD,MAX,MIN,AVER,LJHD,SDB) values('" + djdmstr + "','" + strjh + "'," +
                    "'" + CWStr + "'," + dlX + "," + dlY + "," + djsdfl1 + "," + djsdfl2 + "," + hdfl + ",'" + maxf + "','" + minf + "'," + avel + "," + ljzl + "," + sdbf + ")";
                
                return bll.inserData(inser);
            }
            catch
            {
                return false;
            }

        }

        /// <summary>
        /// 向xmk_a_z_ny02中插入暗色泥岩统计数据
        /// </summary>
        /// <param name="djdmstr">统计代码，形如hjy/2004-10-11/暗色泥岩</param>
        /// <param name="strjh">井号</param>
        /// <param name="CWStr">层位</param>
        /// <param name="dlX">井的Ｘ坐标值</param>
        /// <param name="dlY">井的Ｙ坐标值</param>
        /// <param name="djsdfl1">顶界深度</param>
        /// <param name="djsdfl2">底界深度</param>
        /// <param name="numint">每一层的小层数目</param>
        /// <param name="hdfl">厚度，为底界深度－顶界深度</param>
        /// <param name="maxf">最大厚度</param>
        /// <param name="avel">平均厚度</param>
        /// <returns>布尔类型，如果插入为真，则返回ＴＲＵＥ；否则，返回ＦＡＬＳＥ</returns>
        [WebMethod]
        public bool WriteToAsny(string djdmstr, string strjh, string CWStr, double dlX, double dlY, double djsdfl1, double djsdfl2, int numint, double hdfl, double maxf, double avel)
        {
            try
            {
                YQCJDBLL bll = new YQCJDBLL();
                string inser = "insert into xmk_a_z_ny02(TJDM, JH ,CW,ZBX,ZBY,DINGJSD,DIJSD,NUM,HD,MAX,AVER) values('" + djdmstr + "','" + strjh + "'," +
                    "'" + CWStr + "'," + dlX + "," + dlY + "," + djsdfl1 + "," + djsdfl2 + "," + numint + "," + hdfl + "," + maxf + "," + avel + ")";
                
                return bll.inserData(inser);
            }
            catch
            {
                return false;
            }
        }



        /// <summary>
        /// 向xmk_a_z_ny02中插入泥岩统计数据
        /// </summary>
        /// <param name="djdmstr">统计代码，形如hjy/2004-10-11/泥岩</param>
        /// <param name="strjh">井号</param>
        /// <param name="CWStr">层位</param>
        /// <param name="dlX">井的Ｘ坐标值</param>
        /// <param name="dlY">井的Ｙ坐标值</param>
        /// <param name="djsdfl1">顶界深度</param>
        /// <param name="djsdfl2">底界深度</param>
        /// <param name="hdfl">厚度，为底界深度－顶界深度</param>
        /// <param name="maxf">最大厚度</param>
        /// <param name="minf">最小厚度</param>
        /// <param name="avel">平均厚度</param>
        /// <param name="ljzl">累计厚度</param>
        /// <param name="sdbf">泥地比</param>
        /// <returns>布尔类型，如果插入为真，则返回ＴＲＵＥ；否则，返回ＦＡＬＳＥ</returns>
        [WebMethod]
        public bool WriteToDBN(string djdmstr, string strjh, string CWStr, double dlX, double dlY, double djsdfl1, double djsdfl2, double hdfl, double maxf, double minf, double avel, double ljzl, double sdbf)
        {
            try
            {
                YQCJDBLL bll = new YQCJDBLL();
                string inser = "insert into xmk_a_z_ny01(DJDM, JH ,CW,ZBX,ZBY,DINGJSD,DIJSD,HD,MAX,MIN,AVER,LJHD,SDB) values('" + djdmstr + "','" + strjh + "'," +
                    "'" + CWStr + "'," + dlX + "," + dlY + "," + djsdfl1 + "," + djsdfl2 + "," + hdfl + "," + maxf + "," + minf + "," + avel + "," + ljzl + "," + sdbf + ")";
               
                return bll.inserData(inser);
            }
            catch
            {
                return false;
            }
        }

        /// <summary>
        /// 判断记录集中是否存在数据．
        /// </summary>
        /// <param name="sqlstr">传入ＳＱＬ语句</param>
        /// <returns>布尔类型，如果插入为真，则返回ＴＲＵＥ；否则，返回ＦＡＬＳＥ</returns>
        [WebMethod]
        public bool Isexist(string sqlstr)
        {
            DataSet ds = GetDataSet(sqlstr);
            int number = ds.Tables[0].Rows.Count;
            if (number == 0)
                return false;
            else
                return true;
        }

        /// <summary>
        /// 向xmk_a_z_zj03中插入探井工程量统计数据
        /// </summary>
        /// <param name="user">统计人信息</param>
        /// <param name="jhstr">井号</param>
        /// <param name="stryc">油层</param>
        /// <param name="strjb">井别</param>
        /// <param name="num">统计数目</param>
        /// <param name="dlWZJS">完钻井深</param>
        /// <param name="dlJC">取心进尺</param>
        /// <param name="strQXCW1">取心层位１</param>
        /// <param name="strQXCW2">取心层位２</param>
        /// <param name="dlYXCD">岩心长度</param>
        /// <param name="dlSHL">收获率</param>
        /// <returns>布尔类型，如果插入为真，则返回ＴＲＵＥ；否则，返回ＦＡＬＳＥ</returns>
        [WebMethod]
        public bool WriteToZJ(string user, string jhstr, string stryc, string strjb, int num, double dlWZJS, double dlDJSD1, double dlDJSD2, double dlJC, string strQXCW1, string strQXCW2, double dlYXCD, double dlSHL)
        {
            YQCJDBLL bll = new YQCJDBLL();
            try
            {

                string inser = @"insert into xmk_a_z_zj03(JH,YC,JB,ZJS,WZJS,DJSD1,DJSD2,QXJC,YXCD,SHL,QXCW1,QXCW2,TJR) 
                values('" + jhstr + "','" + stryc + "'," + "'" + strjb + "'," + num + "," + dlWZJS + "," + dlDJSD1 + "," + dlDJSD2 + "," + dlJC + "," + dlYXCD + "," + dlSHL + ",'" + strQXCW1 + "','" + strQXCW2 + "','" + user + "')";

                return bll.inserData(inser);
            }
            catch
            {
                return false;
            }
        }
    }
}
